<template>
  <div class="dashboard-container">
    <el-row :gutter="10">
      <el-col :xs="24" :sm="12" :md="8" :lg="8" :xl="8" class="container-item">
        <card-carouel title="快捷方式" class="shortcut">
          <div slot="content">
            <el-carousel-item class="clearfix" v-for="(item, k) in Math.ceil(shortcut.length / 8)" :key="k">
              <el-col :xs="6" :sm="6" v-for="(item, i) in 8" :key="i" :vd="8 * k + i" v-if="8 * k + i < shortcut.length">
                <router-link :to="{'name': shortcut[8 * k + i]['name'] || shortcut[8 * k + i]['patch']}" class="icon-link">
                  <div class="icon-bg">
                    <svg-icon :icon-class="shortcut[8 * k + i]['icon']" />
                  </div>
                  <cite>{{ shortcut[8 * k + i]['title'] }}</cite>
                </router-link>
              </el-col>
            </el-carousel-item>
          </div>
        </card-carouel>
      </el-col>
      <el-col :xs="24" :sm="12" :md="8" :lg="8" :xl="8" class="container-item">
        <card-carouel title="待办事项" class="todo-list">
          <div slot="content">
            <el-carousel-item class="clearfix" v-for="(item, k) in Math.ceil(todoList.length / 4)" :key="k">
              <el-col :xs="12" :sm="12" v-for="(item, i) in 4" :key="i" :vd="4 * k + i" v-if="4 * k + i < todoList.length">
                <router-link :to="{'name': 'Icon'}" class="todo-link">
                  <div class="todo-bg" :type="todoList[4 * k + i]['type']">
                    <cite>{{ todoList[4 * k + i]['title'] }}</cite>
                    <div class="item-num">{{ todoList[4 * k + i]['number'] }}</div>
                  </div>
                </router-link>
              </el-col>
            </el-carousel-item>
          </div>
        </card-carouel>
      </el-col>
      <el-col :xs="24" :sm="12" :md="8" :lg="8" :xl="8" class="container-item">
        <card-carouel title="待办事项">
          <div slot="content">
            <el-carousel-item>
              <table class="table">
                <tr>
                  <td>当前版本</td>
                  <td> {{ version }} <router-link :to="{'name': 'Icon'}">更新日志</router-link></td>
                </tr>
                <tr>
                  <td>基于框架</td>
                  <td> element-ui {{ vueVersion }}</td>
                </tr>
                <tr>
                  <td>主要特色</td>
                  <td>单页面 / 响应式 / 清爽 / 极简</td>
                </tr>
                <tr>
                  <td>获取渠道</td>
                  <td>
                    <el-button type="warning" size="small">获取授权</el-button>
                    <el-button type="primary" size="small">立即下载</el-button>
                  </td>
                </tr>
              </table>
            </el-carousel-item>
          </div>
        </card-carouel>
      </el-col>
      <el-col :xs="24" :md="16" class="container-item">
        <card-carouel title="数据概览" height="340px">
          <div slot="content">
            <el-carousel-item>
              <line-chart :chart-data="lineChartData"></line-chart>
            </el-carousel-item>
          </div>
        </card-carouel>
      </el-col>
      <el-col :xs="24" :sm="12" :md="8" :lg="8" :xl="8" class="container-item">
        <card-carouel title="实时监控" height="130px">
          <div slot="content">
            <el-carousel-item>
              <div class="progress-item">
                <p class="item-title">CPU使用率</p>
                <el-progress :percentage="99"></el-progress>
              </div>
              <div class="progress-item">
                <p class="item-title">内存占用率</p>
                <el-progress :percentage="66" status="exception"></el-progress>
              </div>
            </el-carousel-item>
          </div>
        </card-carouel>
      </el-col>
      <el-col :xs="24" :sm="12" :md="8" :lg="8" :xl="8" class="container-item">
        <card-carouel title="效果报告" height="130px">
          <div slot="content">
            <el-carousel-item>
              <div class="progress-item">
                <p class="item-title">CPU使用率</p>
                <el-progress :percentage="99"></el-progress>
              </div>
              <div class="progress-item">
                <p class="item-title">内存占用率</p>
                <el-progress :percentage="66" status="exception"></el-progress>
              </div>
            </el-carousel-item>
          </div>
        </card-carouel>
      </el-col>
      <el-col :xs="24" :sm="12" :md="8" :lg="8" :xl="8" class="container-item">
        <card-carouel title="饼状图" height="285px">
          <div slot="content">
            <el-carousel-item>
              <pie-chart></pie-chart>
            </el-carousel-item>
          </div>
        </card-carouel>
      </el-col>
      <el-col :xs="24" :sm="12" :md="8" :lg="8" :xl="8" class="container-item">
        <card-carouel title="柱状图" height="285px">
          <div slot="content">
            <el-carousel-item>
              <bar-chart height="290px"></bar-chart>
            </el-carousel-item>
          </div>
        </card-carouel>
      </el-col>
      <el-col :xs="24" :sm="12" :md="8" :lg="8" :xl="8" class="container-item">
        <card-carouel title="饼状图" height="285px">
          <div slot="content">
            <el-carousel-item>
              <scatter-linear></scatter-linear>
            </el-carousel-item>
          </div>
        </card-carouel>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import CardCarouel from '@/components/CardCarouel'
import LineChart from '@/components/Charts/LineChart'
import PieChart from '@/components/Charts/PieChart'
import BarChart from '@/components/Charts/BarChart'
import ScatterLinear from '@/components/Charts/ScatterLinear'

const lineChartData = {
  newVisitis: {
    expectedData: [100, 120, 161, 134, 105, 160, 165],
    actualData: [120, 82, 91, 154, 162, 140, 145]
  },
  messages: {
    expectedData: [200, 192, 120, 144, 160, 130, 140],
    actualData: [180, 160, 151, 106, 145, 150, 130]
  },
  purchases: {
    expectedData: [80, 100, 121, 104, 105, 90, 100],
    actualData: [120, 90, 100, 138, 142, 130, 130]
  },
  shoppings: {
    expectedData: [130, 140, 141, 142, 145, 150, 160],
    actualData: [120, 82, 91, 154, 162, 140, 130]
  }
}

export default {
  name: 'dashboard',
  components: {
    CardCarouel,
    LineChart,
    PieChart,
    BarChart,
    ScatterLinear
  },
  data() {
    return {
      version: '1.0.0.dev',
      vueVersion: '2.x',
      shortcut: [
        {
          name: 'Icon',
          patch: '/icon',
          title: '图标',
          icon: 'icon'
        },
        {
          name: 'Icon',
          patch: '/',
          title: 'BUG',
          icon: 'bug'
        },
        {
          name: 'Icon',
          patch: '/',
          title: '图标',
          icon: 'chart'
        },
        {
          name: 'Icon',
          patch: '/',
          title: 'CRM',
          icon: 'crm'
        },
        {
          name: 'Icon',
          patch: '/',
          title: '移动',
          icon: 'drag'
        },
        {
          name: 'Icon',
          patch: '/',
          title: '眼睛',
          icon: 'eye'
        },
        {
          name: 'Icon',
          patch: '/',
          title: '星星',
          icon: 'star'
        },
        {
          name: 'Icon',
          patch: '/',
          title: '样式',
          icon: 'theme'
        },
        {
          name: 'Icon',
          patch: '/',
          title: '流程',
          icon: 'tree'
        }
      ],
      todoList: [
        {
          title: '待审评论',
          number: 99,
          type: 'success'
        },
        {
          title: '待审帖子',
          number: 32,
          type: 'info'
        },
        {
          title: '待审商品',
          number: 20,
          type: 'warning'
        },
        {
          title: '待发货',
          number: 14,
          type: 'danger'
        },
        {
          title: '待审友情链接',
          number: 2,
          type: ''
        }
      ],
      lineChartData: lineChartData.newVisitis
    }
  },
  computed: {
    ...mapGetters([
      'name',
      'roles'
    ])
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
@import "src/styles/variables.scss";

.dashboard {
  &-container {
    .el-col.container-item{
      margin-bottom: 10px;
      // 快捷方式
      .todo-list,
      .shortcut{
        .todo-link,
        .icon-link{
          display: block;
          padding: 0;
          .todo-bg,
          .icon-bg{
            height: 60px;
            line-height: 70px;
            border-radius: 3px;
            text-align: center;
            background-color: #F8F8F8;
            .svg-icon{
              width: 25px;
              height: 25px;
            }
            &:hover{
              background-color: #6a8abe;
              box-shadow: 0 5px 0 darken(#6a8abe, 10%);
              .svg-icon{
                color: #FFF;
              }
            }
          }
          cite{
            display: block;
            color: #666;
            font-size: 14px;
            line-height: 30px;
            margin-bottom: 5px;
            font-style: normal;
            text-align: center;
            text-overflow: ellipsis;
            overflow: hidden; 
            white-space: nowrap; 
          }
          .todo-bg{
            height: auto;
            padding: 10px 15px;
            margin-bottom: 10px;
            text-align: left;
            cite{
              margin: 0;
              font-size: 12px;
              line-height: 26px;
              text-align: left;
            }
            .item-num{
              font-size: 30px;
              line-height: normal;
            }
            &:hover{
              &[type="success"]{
                background-color: #67c23a;
                box-shadow: 0 5px 0 darken(#67c23a, 10%);
              }
              &[type="info"]{
                background-color: #909399;
                box-shadow: 0 5px 0 darken(#909399, 10%);
              }
              &[type="warning"]{
                background-color: #cf9236;
                box-shadow: 0 5px 0 darken(#cf9236, 10%);
              }
              &[type="danger"]{
                background-color: #f56c6c;
                box-shadow: 0 5px 0 darken(#f56c6c, 10%);
              }
              &[type="primary"]{
                background-color: #409eff;
                box-shadow: 0 5px 0 darken(#409eff, 10%);
              }
              cite{
                color: #FFF;
              }
              color: #FFF;
            }
          }
        }
      }
      // 实时监控 开始
      .progress-item{
        margin-bottom: 40px;
        .item-title{
          font-size: 14px;
          margin: 10px 0 0;
        }
      }
      // 实时监控 结束
    }
  }
}
</style>
